
<template>
  <H1>员工列表练习</H1>
  <input type="text" placeholder="请输入员工姓名" v-model="user.name"> <br>
  <input type="text" placeholder="请输入员工工资" v-model="user.salary"> <br>
  <input type="text" placeholder="请输入员工姓名" v-model="user.job"> <br>
  <button @click="add">点击添加</button>
  <hr>
  <table border="1px">
    <tr>
      <th>员工编号</th>
      <th>员工姓名</th>
      <th>员工工资</th>
      <th>员工岗位</th>
    </tr>
    <tr v-for="(item,index) in empArr">
      <td>{{index+1}}</td>
      <td>{{item.name}}</td>
      <td>{{item.salary}}</td>
      <td>{{item.job}}</td>
    </tr>
  </table>
</template>

<script setup>
  import {ref} from "vue";
  const empArr = ref([])
  const user = ref({
    name : '',
    salary : '',
    job :''
  });
  const add = ()=>{
    if (user.value.name || user.value.salary || user.value.job){
      empArr.value.push(user.value);
      user.value = {
        name : '',
        salary : '',
        job :''}
    }else alert('不能为空')
  }
</script>

<style scoped>

</style>